package com.link.base.base.projectmanage.controller;

import com.link.base.base.projectmanage.model.TaskInfo;
import com.link.base.base.projectmanage.service.TaskInfoService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 拜访信息
 *
 * @author 刘启鑫
 * @date 2020-09-11 16:52:46
 */
@Controller
@RequestMapping("/link/taskInfo")
public class TaskInfoController extends BasicController<TaskInfo> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private TaskInfoService taskInfoService;

    @Override
    public BasicService<TaskInfo> getBasicService() throws Exception {
        return taskInfoService;
    }

    /**
     * 拜访计划总报表
     * 查询登录用户指定时间区间内，所有车型登记拜访计划
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/visitInfoAllReport",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> visitInfoAllReport(@JsonParam TaskInfo entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            List<TaskInfo> taskInfos = taskInfoService.queryAllByDateRange(entity);
            result.put("success",true);
            //将cha返回
            result.put("newRow",taskInfos);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }

    /**
     * 车型拜访计划报表
     * 根据车型头，查询车型拜访计划 倒序
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/taskInfoCarReport",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> taskInfoCarReport(@JsonParam TaskInfo entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            List<TaskInfo> taskInfos = taskInfoService.queryAllByHeadId(entity);
            result.put("success",true);
            //将cha返回
            result.put("newRow",taskInfos);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }

}